package com.bw.car.page

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.base.path.RouterPath
import com.bw.car.R
import com.bw.car.adapter.StopRecordAdapter
import com.bw.car.databinding.ActivityStopPaymentBinding
import com.bw.car.vm.CarPayViewModel
import com.bw.common.view.BaseMvvmActivity
import com.github.gzuliyujiang.wheelpicker.DatePicker
import com.github.gzuliyujiang.wheelpicker.entity.DateEntity
import dagger.hilt.android.AndroidEntryPoint
@Route(path = RouterPath.PATH_STOP_PATH)
@AndroidEntryPoint
class StopPaymentActivity : BaseMvvmActivity<ActivityStopPaymentBinding>() {
    override fun getLayoutId(): Int = R.layout.activity_stop_payment
    private val mViewModel:CarPayViewModel by viewModels()
    val adapter = StopRecordAdapter()
    var stopCarDate = ""

    override fun initViews() {
        super.initViews()
        mDataBinding.ivDateTime.setOnClickListener {
            val dataPicker = DatePicker(this)
            dataPicker.setTitle("请选择时间")
            dataPicker.wheelLayout.setRange(DateEntity.target(2025,1,1), DateEntity.today())
            dataPicker.setOnDatePickedListener { year, month, day ->
                val date = "${year}/ ${month}"
                stopCarDate = date
                mDataBinding.tvDateTime.setText(date)
                mViewModel.getStopCarRecordData()

            }
            dataPicker.show()
        }
        mDataBinding.rv.adapter = adapter
        mViewModel.getStopCarRecordData()


    }

    override fun loadData() {
        super.loadData()
        mViewModel.mStopCarSuccess.observe(this){
            adapter.data.addAll(it.reversed())
            //adapter.data.addAll(it.filter { it.entryTime.substring(0..7).contains(mDataBinding.tvDateTime.text.toString()) })
            adapter.notifyDataSetChanged()
        }

    }

}